package com.yj.springbootasync.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

@Service
@Slf4j
public class TestService {


    public void sleep(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    // 同步执行
    public void syncMethod(){
        sleep();
    }

    // 异步执行
    @Async("asyncThreadPoolExecutor")
    public Future asyncMethod(){
        sleep();
        log.info("异步方法内部线程名称：{}",Thread.currentThread().getName());
        return new AsyncResult("hello async");
    }

}
